<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Cetak extends zulController {
	function __construct(){
		parent::__construct();
		$this->load->library("form_validation");
		$this->checkLogin();
	}
	public function index()
	{
		$pilihan = $this->input->post("pilihan");
		if($pilihan == 2){
			$this->form_validation->set_rules("tgl_awal","Tanggal Awal","required");
			$this->form_validation->set_rules("tgl_akhir","Tanggal Akhir","required");
		} else {
			$this->form_validation->set_rules("batas_atas","Batas Atas","numeric");
			$this->form_validation->set_rules("batas_bawah","Batas Bawah","numeric");
		}
		$this->form_validation->set_error_delimiters('<div class="alert alert-error fade in">', '</div>');
		$this->form_validation->set_message('required','Kolom %s harus diisi !');
		$this->form_validation->set_message('numeric','Kolom %s harus berupa angka !');
		if($this->form_validation->run() == FALSE){
			$data["active"] = "data";
			$data["content"]	= $this->load->view("form_cetak",$data,true);
			$this->load->view('main_new',$data);
		} else {
			$this->load->library('phpexcel');
			$this->load->library('PHPExcel/iofactory');
			
			$ba = $this->input->post("batas_atas");
			$bb = $this->input->post("batas_bawah");
			if($pilihan == 1){
				$this->load->model('absensi_mahasiswa_model');
				$data["qabsensi"] = $this->absensi_mahasiswa_model->get_absensi($ba,$bb);
				$this->load->view("cetak_absensi",$data);
			} else {
				$this->load->model('master_mahasiswa_model');
				$this->load->model('master_tahun_ajaran_model');
				$this->load->model('cuti_mahasiswa_model');
				$this->load->model('sp_mahasiswa_model');
				$this->load->model('semester_mahasiswa_model');
				$data["tgl_ajar"]	= $this->input->post("tgl_awal");
				$join=array(
					array("table"=>"sp_mahasiswa","join_key"=>"ID_MAHASISWA","join_table"=>"master_mahasiswa")
				);
				// $data["qcuti"] = $this->cuti_mahasiswa_model->get_join_by($join,FALSE,FALSE,array("NAMA","NRP","TANGGAL_SP","KETERANGAN"));
				$data["qsp"] = $this->sp_mahasiswa_model->get_join_by($join,FALSE,FALSE,array("NAMA","NRP","TANGGAL_SP","KETERANGAN"));
				$join=array(
					array("table"=>"cuti_mahasiswa","join_key"=>"ID_MAHASISWA","join_table"=>"master_mahasiswa"),
					array("table"=>"cuti_mahasiswa","join_key"=>"ID_TAHUN_AJARAN","join_table"=>"master_tahun_ajaran")
				);
				$data["qtahun_ajaran"] = $this->master_tahun_ajaran_model->get();
				$data["qcuti"] = $this->cuti_mahasiswa_model->get_join_by($join,FALSE,FALSE,FALSE);				
				$data["qmahasiswa"] = $this->master_mahasiswa_model->get();
				$this->load->view("cetak_chart_mahasiswa",$data);
			}
		}
	}
}